/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.telsoft.security.managedbean.function;

import com.telsoft.security.business.SEC_BU_GROUP_RIGHT;
import com.telsoft.security.business.SEC_BU_Group;
import com.telsoft.security.business.SEC_BU_Right;
import com.telsoft.security.entity.SEC_ETT_Group;
import com.telsoft.security.entity.SEC_ETT_Right;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author nguyenthang
 */
@ManagedBean(name = "func_admin_group")
@SessionScoped
public class SEC_FUNC_Group implements Serializable {

    private SEC_ETT_Group group;
    private SEC_ETT_Group groupItem;
    private Map<String, Integer> selectedRight;
    private List<SEC_ETT_Group> listGroups;
    private List<SEC_ETT_Right> listRights;
    private List<SEC_ETT_Right> listRightsSelect;
    private Boolean isSelect;
    private List<String> activeState;
    private String dialogState;
    private Boolean isAdd;
    private Boolean isEdit;
    private Boolean ctrAdd;
    private Boolean ctrEdit;
    private Boolean ctrDel;
    
    public SEC_FUNC_Group() {
        activeState = new ArrayList<String>();
        listGroups = new ArrayList<SEC_ETT_Group>();
        listGroups = SEC_BU_Group.getAllGroup();
        isAdd = false;
        isEdit = false;
        ctrAdd = true;
        ctrEdit = false;
        ctrDel = false;
        group = new SEC_ETT_Group();
        groupItem = new SEC_ETT_Group();
        selectedRight = new HashMap<String, Integer>();
        listRights = new ArrayList<SEC_ETT_Right>();
        listRightsSelect = new ArrayList<SEC_ETT_Right>();
        listRights = SEC_BU_Right.getAllRight();
        for (SEC_ETT_Right right : listRightsSelect){
            selectedRight.put(right.getRIGHT_NAME(), right.getRIGHT_ID());
        }
        for (SEC_ETT_Group g : listGroups) {
            if (g.getSTATUS() == 0) {
                activeState.add("Disabled");
            } else {
                activeState.add(("Enabled"));
            }
        }
    }

    public void handAdd() {
        isAdd = true;
        isEdit = false;
        dialogState = "Add New Groups";
        group = new SEC_ETT_Group();
        ctrAdd = true;
        ctrEdit = false;
        ctrDel = false;
    }

    public void handEdit() {
        isEdit = true;
        isAdd = false;
        dialogState = "Edit Infomation of Groups";
        groupItem = group;
        ctrAdd = true;
        ctrEdit = false;
        ctrDel = false;
    }

    public void handDelete() {
        ctrDel = false;
        ctrEdit = false;
        ctrAdd = true;
        SEC_BU_GROUP_RIGHT.deleteGRByID(group.getGROUP_ID());
        SEC_BU_Group.deleteGroupByID(group.getGROUP_ID());
    }

    public void handOk() {
        if (isEdit) {
        }
        if (isAdd) {
        }
        ctrAdd = true;
        ctrEdit = true;
        ctrDel = true;
    }

    public void onRowSelect() {
        isSelect = true;
        ctrDel = true;
        ctrEdit = true;
    }

    public void setSelectedRight(Map<String, Integer> selectedRight) {
        this.selectedRight = selectedRight;
    }

    public Map<String, Integer> getSelectedRight() {
        return selectedRight;
    }
    public SEC_ETT_Group getGroup() {
        return group;
    }

    public List<SEC_ETT_Group> getListGroups() {
        return listGroups;
    }

    public void setGroup(SEC_ETT_Group group) {
        this.group = group;
    }

    public void setListRights(List<SEC_ETT_Right> listRights) {
        this.listRights = listRights;
    }

    public List<SEC_ETT_Right> getListRights() {
        return listRights;
    }

    public void setListGroups(List<SEC_ETT_Group> listGroups) {
        this.listGroups = listGroups;
    }

    public Boolean getIsSelect() {
        return isSelect;
    }

    public void setIsSelect(Boolean isSelect) {
        this.isSelect = isSelect;
    }

    public List<String> getActiveState() {
        return activeState;
    }

    public String getDialogState() {
        return dialogState;
    }

    public void setActiveState(List<String> activeState) {
        this.activeState = activeState;
    }

    public void setDialogState(String dialogState) {
        this.dialogState = dialogState;
    }

    public void setGroupItem(SEC_ETT_Group groupItem) {
        this.groupItem = groupItem;
    }

    public void setIsAdd(Boolean isAdd) {
        this.isAdd = isAdd;
    }

    public void setIsEdit(Boolean isEdit) {
        this.isEdit = isEdit;
    }

    public void setCtrAdd(Boolean ctrAdd) {
        this.ctrAdd = ctrAdd;
    }

    public void setCtrEdit(Boolean ctrEdit) {
        this.ctrEdit = ctrEdit;
    }

    public void setCtrDel(Boolean ctrDel) {
        this.ctrDel = ctrDel;
    }

    public SEC_ETT_Group getGroupItem() {
        return groupItem;
    }

    public Boolean getIsAdd() {
        return isAdd;
    }

    public Boolean getIsEdit() {
        return isEdit;
    }

    public Boolean getCtrAdd() {
        return ctrAdd;
    }

    public Boolean getCtrEdit() {
        return ctrEdit;
    }

    public Boolean getCtrDel() {
        return ctrDel;
    }

    public void cancel() {
        if (!isSelect) {
            ctrDel = false;
            ctrEdit = false;
        } else {
            ctrDel = true;
            ctrEdit = true;
        }
    }

    public List<SEC_ETT_Right> getListRightsSelect() {
        return listRightsSelect;
    }

    public void setListRightsSelect(List<SEC_ETT_Right> listRightsSelect) {
        this.listRightsSelect = listRightsSelect;
    }
    
}
